package nancal.mp.db.mongo.entity.dev

import com.fasterxml.jackson.annotation.JsonIgnore
import com.zaxxer.hikari.HikariDataSource
import nbcp.base.comm.StringMap
import nbcp.base.db.annotation.Cn
import nbcp.base.db.annotation.DbEntityGroup
import nbcp.base.model.BaseMarkEntity
import nbcp.base.utils.UrlUtil
import org.springframework.data.mongodb.core.mapping.Document


@Cn("Es数据连接")
@Document
@DbEntityGroup("dev")
data class EsConnection(
    @Cn("名称") var name: String = "",
    @Cn("Ip") var host: String = "",
    @Cn("端口") var port: Int = 9200,
    @Cn("用户名") var userName: String = "",
    @Cn("密码") var password: String = "",
    @Cn("备注") var remark: String = "",
    var code: String = "",
    @Cn("表元数据定义") var tableMetas: MutableMap<String, TableMeta> = mutableMapOf(),
) : BaseMarkEntity() {

    val connectionUri: String
        get() {
            if (userName.isEmpty()) {
                return "http://${host}:${port}"
            }
            return "http://${userName}:${UrlUtil.encodeURIComponent(password)}@${host}:${port}"
        }
}